package com.youdoneed.community.forum.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forum.entity.Forumreportreason;
import com.youdoneed.community.forum.service.ForumreportreasonService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "/forumReportReason", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "论坛举报模块控制器", description = "论坛举报模块相关操作")
public class ForumreportreasonController {

    /**
     * 举报原因删除状态
     */
    public static int deleteStatus = 1;

    private static final Logger logger = LoggerFactory.getLogger(ForummessagelabelController.class);

    @Autowired
    ForumreportreasonService forumreportreasonService;

    /**
     * 逻辑删除举报原因枚举值
     *
     * @param id
     * @return ResultMessage
     * @author lid
     * @date 2017.6.9
     */
    @RequestMapping(value = "/deleteForumReportReason", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台删除举报原因", value = "后台删除举报原因")
    public ResultMessage<?> deleteForumReportReasonById(String id) {
        if (!StringUtils.hasText(id)) {
            return ResultMessage.newFailure("id参数为空！");
        }
        logger.info("根据id" + id + "删除记录");

        Forumreportreason reason = forumreportreasonService.selectForumReportReasonById(id);
        reason.setReasonStatus(deleteStatus);
        forumreportreasonService.updateForumReportReason(reason);
        return ResultMessage.newSuccess("后台删除举报原因成功！");
    }

    @RequestMapping(value = "/saveForumReportReason", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台保存举报原因", value = "后台保存举报原因")
    public ResultMessage<?> insertForumReportReasonLable(@RequestBody Forumreportreason forumreportreason) {
        logger.info("保存记录");

        forumreportreasonService.saveForumReportReason(forumreportreason);
        return ResultMessage.newSuccess("后台保存举报原因成功!");

    }

    @RequestMapping(value = "/getForumReportReason", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台查询举报原因", value = "后台查询举报原因")
    public ResultMessage<Forumreportreason> selectForumReportReasonById(String id) {
        logger.info("查询记录");
        Forumreportreason reason = forumreportreasonService.selectForumReportReasonById(id);
        return ResultMessage.newSuccess("后台保存举报原因成功!").setData(reason);
    }

    @RequestMapping(value = "/updateForumReportReason", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台修改举报原因", value = "后台修改举报原因")
    public ResultMessage<?> updateForumReportReason(@RequestBody Forumreportreason forumreportreason) {
        logger.info("保存记录");
        forumreportreasonService.updateForumReportReason(forumreportreason);
        return ResultMessage.newSuccess("后台修改举报原因成功");
    }

    /**
     * APP端获取举报原因
     *
     * @return ResultMessage
     * @author lid
     * @date 2017.6.12
     */
    @RequestMapping(value = "/getForumReportReasonOnLine", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "APP端获取举报原因", value = "APP端获取举报原因")
    public ResultMessage<List<Forumreportreason>> getForumReportReasonOnLine() {
        logger.info("APP端获取举报原因");
        List<Forumreportreason> listForumreportreason = forumreportreasonService.selectOnLineReportReason();
        if (null == listForumreportreason) {
            return ResultMessage.newFailure("APP端获取举报原因失败!");
        }
        return ResultMessage.newSuccess("APP端获取举报原因成功!").setData(listForumreportreason);
    }

}
